const mysql = require("mysql2");

const connectionPool = mysql.createPool({
  host: process.env.MLSQL_POOL_HOST,
  port: process.env.MLSQL_POOL_PORT,
  database: process.env.MLSQL_POOL_DATABASE,
  user: process.env.MLSQL_POOL_USER,
  password: process.env.MLSQL_POOL_PASSWORD,
  connectionLimit: 5,
});

console.log("数据库连接中...");
connectionPool.getConnection((err, connection) => {
  console.log(`db_blogs，数据库连接${err ? "失败" : "成功"} ~`);
  console.log("尝试与数据库交互...");
  connection.connect((err) => {
    console.log(`与数据库交互${err ? "失败" : "成功"} ~`);
  });
});

module.exports = connectionPool.promise();
